﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Neotic.DataAccess.Sql.Operations
{
    public class Count : ISelectColumn
    {
        private Column _c = null;
        protected string _aliasName;

        /// <summary>
        /// correspond au count (*)
        /// </summary>
        public Count() { }

        /// <summary>
        /// correspond au count ([Column])
        /// </summary>
        public Count(Column c) { _c = c; }

        public string FullName
        {
            get { return (_c == null)?"Count(*)":string.Concat("count(", _c.FullName, ")"); }
        }

        public string AliasName
        {
            get
            {
                return string.IsNullOrWhiteSpace(_aliasName) ? this.FullName : _aliasName;
            }
        }

        public string FullAliasName
        {
            get
            {
                return (string.IsNullOrWhiteSpace(_aliasName) ? this.FullName : string.Concat(this.FullName, " as '", _aliasName, "'"));
            }
        }

        public ISelectColumn As(string aliasName)
        {
            _aliasName = aliasName;
            return this;
        }

        public OrderClauseColumn Ascending { get { return new OrderClauseColumn(this, true); } }
        public OrderClauseColumn Descending { get { return new OrderClauseColumn(this, true); } }

    }
}
